import defaultSettings from '@/settings'

const { showSettings, fixedHeader, sidebarLogo } = defaultSettings

const url = window.location.host
let httpsUrl = `https://${url}/`
let encryption = true
// if (window && (window.location.href.indexOf("localhost") > -1 || window.location.href.indexOf("192.168.2") > -1) ) {
//   httpsUrl= "http://192.168.2.10:8305/"
//   // httpsUrl= "https://www.fubaozx.cn/"
//   encryption=false
// }
const state = {
  showSettings: showSettings,
  fixedHeader: fixedHeader,
  sidebarLogo: sidebarLogo,
  key: "福宝",
  logo: "https://pili-vod.guanxikeji.com/fubao/img/1755758365748.png",
  name: "福宝商城",
  mainurl: (() => {
    const host = window.location.host;
    if (host.includes('test')) {
      return 'https://test.fubaozx.cn/';
    } else if(host.includes('www')){
      return 'https://www.fubaozx.cn/';
    }else{
      encryption=false
      return "http://192.168.2.10:8305/"
    }
  })(),

  // mainurl: 'https://www.fubaozx.cn/',
  template: "mb",
  encryption,
}

const mutations = {
  CHANGE_SETTING: (state, { key, value }) => {
    // eslint-disable-next-line no-prototype-builtins
    if (state.hasOwnProperty(key)) {
      state[key] = value
    }
  }
}

const actions = {
  changeSetting({ commit }, data) {
    commit('CHANGE_SETTING', data)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

